from wordcloud import WordCloud
import matplotlib.pyplot as plt
import jieba.analyse as analyse
import pandas as pd
f = '''李白用“举头望明月，低头思故乡”来表达自己的思乡之情；文天祥用“人生自古谁无死，
留取丹心照汗青”来证明他无畏牺牲的精神；纳兰性德则用“人生若只如初见，何事秋风悲画扇”
来抒发他对事物的感慨。我们借助一个个汉字，来表达自己的喜怒哀乐，不同的汉字组成的词句，
所表达出的意义，内涵则也大不相同，这就是属于汉字的独特魅力。
'''
# split_list = jieba.cut_for_search(f)
# g = ' '.join(split_list).split(' ')
# print(g)

# stop = pd.read_csv('hit_stopwords.txt',sep="\t\n",header=None)

# c = []
# for i in g:
#     if i not in stop:
#         c.append(i)
# f2 = ' '.join(c)

# wd = WordCloud()
# wd.generate(f2)
# plt.imshow(wd)
# plt.show()

df = pd.read_csv("1.txt",encoding='utf-8')
df = df.dropna()
lines = df.segment.values.tolist()
content = ' '.join(lines)
keywords = analyse.extract_tags(content,topK=10,withWeight=False,allowPOS=())
print(keywords)
